<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>AJAX之fetch发起cgi请求</title>
        <style>
            
        </style>

    </head>
    <body>
       <button onclick="ajax_get()">发起GET请求</button>
       <script>
        function ajax_get(){
            // 发起请求，接受response类型数据
            fetch("/cgi-bin/data1").then(response=>{
            console.log(response.status);
            if(response.status == 200){
                return response.text();
            }
        }).then(data=>{
            console.log(data);
            data = JSON.parse(data); // 将json字符串转化为js对象
            console.log(data.id,data.msg);
        })
        }
       </script>
    </body>
</html>